package com.lianxian.xindong.login.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hxb.library.base.BaseActivity;
import com.hxb.library.di.component.AppComponent;
import com.hxb.library.utils.HxbUtils;
import com.lianxian.xindong.commonres.weight.ClearEditText;
import com.lianxian.xindong.commonsdk.utils.ImmersionBarUtil;
import com.lianxian.xindong.login.R;
import com.lianxian.xindong.login.R2;
import com.lianxian.xindong.login.di.component.DaggerRegisterComponent;
import com.lianxian.xindong.login.mvp.contract.RegisterContract;
import com.lianxian.xindong.login.mvp.presenter.RegisterPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.hxb.library.utils.Preconditions.checkNotNull;


/**
 * @作者：hexingbo
 * @时间：07/03/2023
 * @描述：
 */
public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterContract.View {

    @BindView(R2.id.et_account_number)
    ClearEditText etAccountNumber;
    @BindView(R2.id.et_account_password)
    ClearEditText etAccountPassword;
    @BindView(R2.id.et_account_password_to)
    ClearEditText etAccountPasswordTo;
    @BindView(R2.id.et_invite_code)
    ClearEditText etInviteCode;
    @BindView(R2.id.btn_register)
    Button btnRegister;
    @BindView(R2.id.iv_login_type_phone)
    ImageView ivLoginTypePhone;
    @BindView(R2.id.iv_login_type_other)
    ImageView ivLoginTypeOther;
    @BindView(R2.id.cb_agreement)
    CheckBox cbAgreement;
    @BindView(R2.id.tv_agreement_service)
    TextView tvAgreementService;
    @BindView(R2.id.tv_agreement_privacy)
    TextView tvAgreementPrivacy;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerRegisterComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_register; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ImmersionBarUtil.setImmersionBar(this, true);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        HxbUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        HxbUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Context getContext() {
        return this;
    }

    @OnClick({R2.id.btn_register, R2.id.iv_login_type_phone, R2.id.iv_login_type_other})
    public void onViewClicked(View view) {
        if (view.getId() == R.id.btn_register) {
            //注册
            mPresenter.submitRegisterData(
                    etAccountNumber.getText().toString(),
                    etAccountPassword.getText().toString(),
                    etAccountPasswordTo.getText().toString(),
                    etInviteCode.getText().toString());
        } else if (view.getId() == R.id.iv_login_type_phone) {
            //手机号登录
            mPresenter.goLoginTypePhone();
        } else if (view.getId() == R.id.iv_login_type_other) {
            //心动号登录
            mPresenter.goLoginTypeOther();
        }
    }

    /**
     * 协议点击事件处理
     *
     * @param view
     */
    @OnClick({R2.id.cb_agreement, R2.id.tv_agreement_service, R2.id.tv_agreement_privacy})
    public void onAgreementViewClicked(View view) {
        if (view.getId() == R.id.cb_agreement) {
            //勾选协议
            mPresenter.checkAgreement(cbAgreement.isChecked());
        } else if (view.getId() == R.id.tv_agreement_service) {
            //使用服务协议
        } else if (view.getId() == R.id.tv_agreement_privacy) {
            //隐私政策
        }
    }


}
